package xyz.zq.validation.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import xyz.zq.validation.entity.User;

import javax.validation.Valid;
import java.util.UUID;

import static xyz.zq.validation.util.HttpUtil.getRequestParameterMap;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @PostMapping
    public User add(@Valid @RequestBody User user,
                    BindingResult result) {

        System.out.println("jin");

        user.setId(UUID.randomUUID());
        return user;
    }

    @GetMapping
    public User query(@RequestParam String username) {

        getRequestParameterMap();

        return new User()
                .setId(UUID.randomUUID())
                .setUsername(username);

    }

}
